# -*- coding: utf8 -*-
# !/usr/bin/env python


""" 参考: 微信小程序 - 下厨房 - 爬虫
    参考: https://mp.weixin.qq.com/s?__biz=MzUxMDc4NTkwMA==&mid=2247484464&idx=1&sn=ce3c483a38641034bc601d513d01c36f&chksm=f97ce433ce0b6d25e5cac47aa9c4881ef17520551e5c42e5b45ffca048f3e4a4919d62ed84fa&token=7447076&lang=zh_CN#rd
"""


from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)

auto_setup(__file__)

# 启动微信app
start_app("com.tencent.mm")

# 下滑进去小程序页面
swipe((550,250),(550,1200))

sleep(2.0)

# 点击 "下厨房APP小程序"
poco("com.tencent.mm:id/cud").offspring("com.tencent.mm:id/dai").child("android.widget.RelativeLayout").offspring("com.tencent.mm:id/le").offspring("com.tencent.mm:id/lh").child("android.widget.LinearLayout")[2].offspring("com.tencent.mm:id/eko").child("android.widget.RelativeLayout")[0].offspring("com.tencent.mm:id/cik").click()

sleep(2.0)

# 点击搜索框
poco(text="今天想吃点什么？").click()

sleep(1.0)

# 再次点击搜索框
poco("android.widget.EditText").click()

sleep(1.0)

# 输入搜索词“蛋糕”
search_text = "蛋糕"
poco("android.widget.EditText").set_text(search_text)

# 点击搜索
poco(text="搜索").click()

# 打印找到第一个配方的标题
print(poco(text="超容易上手的古早蛋糕").get_text())
